程式碼
using System.Collections; using System.Collections.Generic; using UnityEngine; public class AverageArray : MonoBehaviour { // Start is called before the first frame update void Start() { int[] score = { 72, 50, 47, 14, 98, 6, 55, 84 }; int sum = 0; for(int i = 0; i < score.Length; i++) { sum += score[i]; } float average = 1.0f * sum / score.Length; Debug.Log(average); } }
Console輸出
參考來源:Unity 遊戲設計育成攻略